﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sami_SMS_CRM_Business
{
    public class LogRepository : Repository
    {
        public  IList<crm_log> GetAll(int currentPage, int pageSize, ref int totalRecord)
        {
            var retValue = DB.crm_logs.OrderByDescending(l => l.log_time);
            totalRecord = retValue.Count();
            return retValue.Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
        }

        public  void ClearAll()
        {
            DB.ExecuteCommand("TRUNCATE TABLE crm_log");
            DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.crm_logs);
        }

        public  void InsertLog(Exception e)
        {
            DB.crm_logs.InsertOnSubmit(new crm_log()
            {
                log_message = e.Message,
                log_source = e.Source,
                log_stack_trace = e.StackTrace,
                log_time = DateTime.Now
            });
            DB.SubmitChanges();
        }
    }
}
